<?php
/**
 * Created by PhpStorm.
 * User: 张辉
 * Date: 2018/8/28
 * Time: 12:58
 */

/*
 * 用户神策上报队列
 */
namespace app\common\redis;
use app\common\service\ElkLog;
use app\common\service\SensorsData;

class UserSensorsDataRedis extends RedisModel
{
    /**
     * Redis配置名称
     * @var string
     */
    public $redis = 'default';


    /**
     * Redis key
     * @var string
     */
    public $key = 'list:user_sensors_data';

    public $preview_key = 'list:user_sensors_data_preview';

    /**
     * 上报数据
     * @param $user_id
     * @param $report_name
     * @param string $channel
     */
    public function pushUserSensors( $user_id, $report_name, $channel = 'market', $sensor_id = "" )
    {
        // 上报神策数据
        $user_sensors_data = array(
            'user_id' =>  $user_id,
            'report_name' => $report_name
        );

        if ( $sensor_id ){
            $SensorsData = new SensorsData();
            $SensorsData->sa->track_signup( $user_id, $sensor_id );
            ElkLog::write( array( "message"=> "pushUserSensors_track_signup", "user_id"=>$user_id, "sensor_id" => $sensor_id ) );
            $SensorsData->sa->close();
        }

        $this->ListLpush( json_encode( $user_sensors_data ));
    }


}